import random
list1=[]
dict1={}
y3=[]
with open("ips.txt","a+") as f:
    for i in range(120):
        a = random.randint(0, 255)
        f.write(f"172.25.254.{a}/24\n")
with open("ips.txt","r+") as f2:
    line = len(f2.readlines())
    print(line)
with open("ips.txt","r+") as f3:
#将TXT里的IP放进列表去重并统计
    for i in range(line):
        list1.append(f3.readline())
myset= set(list1)
for i in myset:
    counts = list1.count(i)
#放入一个字典，用sorted函数（从小到大）排序,并将队尾放入一个元组
    dict1[i] = counts
y=sorted(dict1.items(),key=lambda x:x[1])
for i in range(10):
    y2 = y.pop()
    print(f"出现次数第{i+1}的是{y2[0]},出现的次数为{y2[1]}")

